#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

const int N = 10010;
int a[N];
int res[N][N];
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int main()
{
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);

    int n, m;
    int k;
    scanf("%d", &k);
    for (int i = 0; i < k; i++)
        scanf("%d", &a[i]);

    sort(a, a + k, greater<int>());

    for (int i = 1; i * i <= k; i++)
        if (k % i == 0)
        {
            m = k / i;
            n = i;
        }

    for (int i = 0, x = 0, y = 0, d = 0; i < k; i++)
    {
        res[x][y] = a[i];
        int xx = x + dx[d], yy = y + dy[d];
        if (xx < 0 || xx >= m || yy < 0 || yy >= n || res[xx][yy])
        {
            d = (d + 1) % 4;
            xx = x + dx[d];
            yy = y + dy[d];
        }
        x = xx;
        y = yy;
    }
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < n; j++)
        {
            printf("%d ", res[i][j]);
        }
        printf("\n");
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
